'use strict';

const Koa = require('koa');
let exp = Object.assign({}, require('./components'), require('./middlewares'));
exp.getApp = (options) => {
  let app = new Koa();
  if (options.vhost) {
    app.use(exp.virtualHost(options.vhost));
  }
  app.use(exp.ip());
  app.use(exp.morgan(options.logger));
  if (options.static) {
    app.use(exp.static(options.static));
  }
  app.use(exp.useragent());
  app.use(exp.bodyParser());
  if (options.session) {
    if (options.session.redis === true) {
      options.session.redis = options.redis;
    }
    app.use(exp.session(options.session));
  }
  return app;
};
exports = module.exports = exp;